package com.wh.hotel.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.google.common.base.Preconditions;
import com.wh.common.annotation.ResultLog;
import com.wh.common.enums.MethodTypeEnum;
import com.wh.common.vo.Result;
import com.wh.hotel.enums.base.HotelOperateTypeEnum;
import com.wh.hotel.model.HotelRoomType;
import com.wh.hotel.param.HotelQueryRoomParam;
import com.wh.hotel.response.HotelRoomDetailResponse;
import com.wh.hotel.service.HotelRoomTypeService;
import com.wh.hotel.vo.HotelRoomTypeVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author wenhao
 */
@RequestMapping("/hotel/room/type")
@RestController
@Slf4j
public class HotelRoomTypeController {

    @Resource
    private HotelRoomTypeService hotelRoomTypeService;


    /**
     * 新增或修改房型
     *
     * @param hotelRoomTypeVo
     * @return
     */
    @PostMapping("/save")
    @ResultLog(name = "HotelRoomTypeController.saveRoomType", methodType = MethodTypeEnum.HTTP_UP)
    public Result<HotelRoomType> saveRoomType(@RequestBody HotelRoomTypeVo hotelRoomTypeVo) {
        Preconditions.checkNotNull(hotelRoomTypeVo.getHotelId(), "酒店ID必填");
        Preconditions.checkNotNull(hotelRoomTypeVo.getBookRuleId(), "预订规则ID必填");
        return Result.successResponse(hotelRoomTypeService.addRoomType(hotelRoomTypeVo));
    }

    /**
     * 上下架房型
     *
     * @param hotelRoomTypeVo
     * @return
     */
    @PostMapping("/updateRoomTypeStatus")
    @ResultLog(name = "HotelRoomTypeController.updateRoomTypeStatus", methodType = MethodTypeEnum.HTTP_UP)
    public Result<Boolean> updateRoomTypeStatus(@RequestBody HotelRoomTypeVo hotelRoomTypeVo) {
        Preconditions.checkNotNull(hotelRoomTypeVo.getHotelId(), "酒店ID必填");
        Preconditions.checkNotNull(hotelRoomTypeVo.getRoomTypeId(), "房型ID必填");
        Preconditions.checkNotNull(HotelOperateTypeEnum.parse(hotelRoomTypeVo.getOperateType()), "操作类型不合法");
        return Result.successResponse(hotelRoomTypeService.updateRoomTypeStatus(hotelRoomTypeVo));
    }

    /**
     * 查询酒店的房型列表
     *
     * @param param
     * @return
     */
    @PostMapping("/list")
    @ResultLog(name = "HotelRoomTypeController.list", methodType = MethodTypeEnum.HTTP_UP)
    public Result<IPage<HotelRoomDetailResponse> > list(@RequestBody HotelQueryRoomParam param) {
        Preconditions.checkNotNull(param.getHotelId(), "酒店ID必填");
        return Result.successResponse(hotelRoomTypeService.queryListRoomInfo(param));
    }

    /**
     * 查询酒店的房型详情
     *
     * @param param
     * @return
     */
    @PostMapping("/detail")
    @ResultLog(name = "HotelRoomTypeController.detail", methodType = MethodTypeEnum.HTTP_UP)
    public Result<HotelRoomDetailResponse> detail(@RequestBody HotelQueryRoomParam param) {
        Preconditions.checkNotNull(param.getRoomTypeId(), "房型ID必填");
        return Result.successResponse(hotelRoomTypeService.queryDetailRoomInfo(param));
    }

}
